# GtkTrayIcon.py
# Copyright (C) otacon 2010 <orfeo18@gmail.com>
# 
# AdSense-Monitor is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# AdSense-Monitor is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.
import gtk

class GtkTrayIcon(gtk.StatusIcon):
    """
    tray icon for AdSense Library
    """
    def __init__(self , icon, tray, gtk_window=None):
        """
        constructor
        """
        gtk.StatusIcon.__init__(self)
        self.connect('popup-menu', self._on_popup)
        self.set_icon(icon)
        self.set_visible(True)

    def set_icon(self,icon):
        self.set_from_file(icon)

    def set_menu(self, menu):
        self.menu = menu
        self.menu.show_all()

    def remove(self):
        self.set_visible(False)

    def _on_popup(self, trayicon, button, activate_time):
        """
        callback called when the popup of the status icon is activated
        (usually through right-clicking the status icon)
        """
        self.menu.popup(None, None, None, button, activate_time)
